package com.hopu.oa.dao.task;

import com.hopu.oa.entity.management.AoaStatusList;
import com.hopu.oa.entity.management.AoaTypeList;
import com.hopu.oa.entity.task.AoaTasklist;
import com.hopu.oa.entity.user.AoaUser;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Secret
 * @create 2021-07-17 上午 09:16
 */
@Mapper
@Repository
public interface TaskDao {

    //分页查询
    List<AoaTasklist> findAllTask(@Param("userId") Integer userId, @Param("title") String title, @Param("index") int index, @Param("size") int size, @Param("var") String var);

    //添加修改
    @Select("SELECT * from aoa_status_list where status_model = 'aoa_task_list' ")
    List<AoaStatusList> selectBytaskList();

    @Select("select * from aoa_type_list where type_model='aoa_task_list'")
    List<AoaTypeList> selectByTypelist();

    List<AoaUser> selectByfatherId(int uid, String userName, int index, int size);

    int insertTaskList(AoaTasklist tasklist);

    @Select("select * from aoa_task_list where task_id =#{id}")
    AoaTasklist selectBytaskId(int id);

    @Select("select * from aoa_status_list where status_id =#{sid}")
    AoaStatusList selectByStatusListId(int sid);

    @Select("select * from aoa_type_list ")
    AoaTypeList selectByLypeId();

    @Update("update aoa_task_list set is_top=#{isTop},type_id=#{typeId},status_id=#{statusId},star_time=#{starTime},end_time=#{endTime},title=#{title},reciverlist=#{reciverlist},task_describe=#{taskDescribe},comment=#{comment},task_push_user_id=#{taskPushUserId} where task_id=#{taskId} ")
    int updateTaskList(AoaTasklist tasklist);

    @Select("select * from aoa_user where user_name = #{name}")
    AoaUser selectUserByUserName(String name);

    //
//    @Insert("insert into aoa_task_user (status_id,task_id,task_recive_user_id) values (#{statusId},#{taskId},#{taskReciveUserId})")
    int insertIntotaskUser(@Param("statusId") int statusId, @Param("taskId") int taskId, @Param("taskReciveUserId") int taskReciveUserId);

    @Insert("insert into aoa_task_logger (create_time,task_id,username,logger_statusid) values(#{starTime},#{taskId},#{username},#{statusId})")
    int insertintoLogger(String starTime, int taskId, String username, int statusId);

    //删除
    @Delete("delete from aoa_task_list where task_id=#{id}")
    int deleteTaskListById(int id);

    @Delete("delete from aoa_task_user where task_id=#{id}")
    int deleteTaskUserById(int id);

    @Delete("delete from aoa_task_logger where task_id=#{id}")
    int deleteTaskLoggerById(int id);

    @Select("select min(status_id) from  aoa_task_user where task_id = #{id}")
    int querystatusIdById(int id);

    List<AoaTasklist> selectTaskUser(@Param("userId") Integer userId);
}
